package com.bckj.fastboot.upms.biz.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bckj.fastboot.core.lang.model.PageResult;
import com.bckj.fastboot.core.page.PageSupport;
import com.bckj.fastboot.upms.api.dto.UserAuthInfo;
import com.bckj.fastboot.upms.api.dto.UserQuery;
import com.bckj.fastboot.upms.api.dto.UserRequest;
import com.bckj.fastboot.upms.api.service.UserRemoteService;
import com.bckj.fastboot.upms.api.vo.UserVO;
import com.bckj.fastboot.upms.biz.service.UserService;
import org.springframework.web.bind.annotation.*;


import lombok.RequiredArgsConstructor;
import java.util.List;


/**
 * 用户表(User)表控制层
 *
 * @author wfc
 * @since 2023-09-14 16:05:36
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("user")
public class UserController implements UserRemoteService {
    /**
     * 服务
     */
	private final UserService userService;
	
    /**
	 * 列表
	 *
	 * @param query req
	 * @return list
	 */
    @Override
	@GetMapping("page")
	public PageResult<UserVO> page(UserQuery query) {
		IPage<UserVO> page = PageSupport.page(() -> userService.list(query));
		return PageResult.of(page);
	}
	
    /**
	 * 列表
	 *
	 * @param query req
	 * @return list
	 */
    @Override
	@GetMapping("list")
	public List<UserVO> list(UserQuery query) {
		return userService.list(query);
	}

	/**
	 * 增加
	 *
	 * @param request req
	 * @return boolean
	 */
	@Override
	@PostMapping
	public boolean save(@RequestBody UserRequest request) {
		return userService.save(request);
	}

	/**
	 * 修改
	 *
	 * @param request req
	 * @return boolean
	 */
	@Override
	@PutMapping
	public boolean update(@RequestBody UserRequest request) {
		return userService.update(request);
	}

	/**
	 * 移除
	 *
	 * @param id id
	 * @return boolean
	 */
	@Override
	@DeleteMapping("{id}")
	public boolean remove(@PathVariable Long id) {
		return userService.remove(id);
	}

	/**
	 * 详情
	 *
	 * @param id id
	 * @return vo
	 */
	@Override
	@GetMapping("{id}")
	public UserVO details(@PathVariable Long id) {
		return userService.details(id);
	}

	@Override
	public UserAuthInfo findByPhone(String phone) {
		return userService.findByPhone(phone);
	}
}

